# 输出斐波那契数列 1，1，2，3，5，8，13...
def fib_rec(n):
    """
    使用递归生成 斐波那契数列
    :param n:
    :return:
    """
    if n < 2:
        return 1
    else:
        return fib_rec(n - 1) + fib_rec(n - 2)


def fib_gen(n):
    i = 0
    x, y = 1, 1
    while i < n:
        yield x
        t = y
        y = x + y
        x = t
        i = i + 1


if __name__ == '__main__':
    # for i in range(10):
    #     print(fib_rec(i))

    # gen = fib_gen(10)
    # for i in range(10):
    #     print(next(gen))

    # 生成器对象可以直接迭代
    for i in fib_gen(10):
        print(i)
